package com.justgame.project.service.just.controller;

import com.justgame.project.base.annotation.ProtectAccess;
import com.justgame.project.cloud.common.constant.Result;
import com.justgame.project.service.api.dto.JustGameTypeDTO;
import com.justgame.project.cloud.common.entity.PageRequest;
import com.justgame.project.service.just.service.JustGameTypeService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/just/game-type")
@AllArgsConstructor
public class JustGameTypeController {

    private final JustGameTypeService gameTypeService;

    @GetMapping("/list")
    public Result<Object> getList(PageRequest pageRequest, JustGameTypeDTO dto) {
        return Result.OK(gameTypeService.getList(pageRequest, dto));
    }

    @PostMapping("/save")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<Object> addGameType(@Valid @RequestBody JustGameTypeDTO dto) {
        return Result.OK(gameTypeService.addGameType(dto));
    }


    @DeleteMapping("/delete")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<Object> deleteGameType(@RequestBody JustGameTypeDTO dto) {
        return Result.OK(gameTypeService.Delete(dto));
    }

    @PostMapping("/updateById")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<Object> updateById(@RequestBody JustGameTypeDTO dto) {
        return Result.OK(gameTypeService.updateById(dto));
    }
}
